<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('物料信息')"/>
	<style>
		.deer-cell {
			border-color: #d3dce6;
			height: 46px;
			border-style: solid;
			z-index: 200000;
			text-align: center;
		}
		.deer-cell .deer-cell-title {
			line-height: 44px;
			font-weight: bold;
			color: #99a9bf;
			width: auto;
		}
		.searchBox{
			width: 50px;
			height: 32px;
			text-align: center;
			line-height: 32px;
			background-color: #409EFF;
			color: #FFFFFF;
			border-radius: 4px;
			display: inline-block;
			cursor: pointer;
		}
		.el-select{
			width: 177px;
		}
	</style>
</head>
<body>
<div class="container-div">
	<el-form label-width="100px" label-position="left" :model="domain" :rules="rules" ref="insertForm" class="demo-ruleForm" :inline="true">
		<el-divider content-position="left" style="margin-bottom: 20px">物料信息</el-divider>
		<div style="margin-left: 5%">
			<div style="display: inline-block">
				<el-form-item size="small" label="物料编码:" prop="itemCode">
					<el-input placeholder="请输入物料编码" size="small" v-model="domain.itemCode"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="描述(规格):" prop="itemName">
					<el-input placeholder="请输入描述" size="small" v-model="domain.itemName"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block;">
				<el-form-item size="small" label="物料分类:" prop="sort">
					<el-select v-model="domain.sort" placeholder="请选择物料分类">
						<el-option label="钢材" value="1"></el-option>
						<el-option label="铜材" value="2"></el-option>
					</el-select>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="基本单位:" prop="baseUnit">
					<el-input placeholder="请输入基本单位" size="small" v-model="domain.baseUnit"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="采购单位:" prop="unit">
					<el-input placeholder="请输入采购单位" size="small" v-model="domain.unit"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="自动采购:" prop="boxAutomatic">
					<el-input placeholder="请输入自动采购" size="small" v-model="domain.boxAutomatic"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="过账检验库存:" prop="boxStock">
					<el-input placeholder="请输入过账检验库存" size="small" v-model="domain.boxStock"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="采购舍入值:" prop="rounding">
					<el-input placeholder="请输入采购舍入值" size="small" v-model="domain.rounding"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="采购人编码:" prop="userCode">
					<el-input placeholder="请输入采购人编码" size="small" v-model="domain.userCode"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="课税:" prop="taxation">
					<el-input placeholder="请输入课税" size="small" v-model="domain.taxation"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="利润中心:" prop="profit">
					<el-input placeholder="请输入利润中心" size="small" v-model="domain.profit"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="采购组:" prop="purchase">
					<el-input placeholder="请输入采购组" size="small" v-model="domain.purchase"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="统计组:" prop="census">
					<el-input placeholder="请输入统计组" size="small" v-model="domain.census"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="最大数量:" prop="max">
					<el-input placeholder="请输入最大数量" size="small" v-model="domain.max"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="最小数量:" prop="min">
					<el-input placeholder="请输入最小数量" size="small" v-model="domain.min"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="高度:" prop="height">
					<el-input placeholder="请输入高度" size="small" v-model="domain.height"></el-input>
				</el-form-item>
			</div>
			<div style="display: inline-block">
				<el-form-item size="small" label="有效期:" prop="time">
					<el-input placeholder="请输入高度" size="small" v-model="domain.time">
						<template slot="append">年</template>
					</el-input>
				</el-form-item>
			</div>
		</div>
	</el-form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/wms/js/date.js}"></script>
<script type="text/javascript" charset="UTF-8">
	var prefix = ctx + "system/itemInfo"
	function submitHandler() {
		app.save();
	}
	var app = new Vue({
		el: '.container-div',
		data() {
			return {
				rules:{
					itemCode: [
						{ required: true, message: '请输入物料编码', trigger: 'change' },
					],
					height: [
						{ required: true, message: '请输入高度', trigger: 'change' },
					],
				},
				domain: {
					boxAutomatic: 'X',
					time: '3',
					oldName: '',
					itemCode: '',
					itemName: '',
					baseUnit: '',
					unit: '',
					boxStock: '',
					rounding: '',
					userCode: '',
					taxation: '',
					profit: '',
					purchase: '',
					census: '',
					sort: '',
					height: '',
					min: '',
					max: ''
				},
				title: '',
				itemId: ''
			}
		},
		methods: {
			//关闭此页面
			closeModal: function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
			},
			save() {
				var that = this;
				this.$refs['insertForm'].validate((valid) => {
					if (valid) {
						console.log(that.domain)
						for (let i in that.domain) {
							console.log(that.domain[i])
							if (that.domain[i] == null) {
								that.domain[i] = ""
							}
						}
						if (that.title == '编辑') {
							$.ajax({
								cache: true,
								url: prefix + "/edit",
								type: 'POST',
								async: false,
								data: that.domain,
								error: function (request) {
									$.modal.alertError("系统错误");
								},
								success: function (data) {
									if(data.code == 0){
										$.modal.msgReload(data.msg, "success")
									}else{
										$.modal.alertError(data.msg);
									}
								}
							})
						} else {
							$.ajax({
								cache: true,
								url: prefix + '/add',
								type: 'POST',
								async: false,
								data: that.domain,
								error: function (request) {
									$.modal.alertError("系统错误");
								},
								success: function (data) {
									if(data.code == 0){
										$.modal.msgReload(data.msg, "success")
									}else{
										$.modal.alertError(data.msg);
									}
								}
							})
						}
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			}
		},
		created(){
			this.title = localStorage.getItem('wltitle');
			this.itemId = localStorage.getItem('/system/itemInfo/add');
			let that = this;
			if (this.title == '编辑') {
				$.ajax({
					cache: true,
					url: prefix + '/findItemById',
					type: 'POST',
					data: {
						itemId: that.itemId
					},
					error: function (request) {
						$.modal.alertError("系统错误");
					},
					success: function (data) {
						console.log(data)
						that.domain = data;
						that.domain.sort = data.sort.toString();
					}
				})
			} else {
				that.domain = {
					boxAutomatic: 'X',
					time: '3',
					oldName: '',
					itemCode: '',
					itemName: '',
					baseUnit: '',
					unit: '',
					boxStock: '',
					rounding: '',
					userCode: '',
					taxation: '',
					profit: '',
					purchase: '',
					census: '',
					sort: '',
					height: '',
					min: '',
					max: ''
				};
			}
		}
	})
</script>
</body>
</html>
